/* ------------------------------------------------------------------ */
/* adj44c-01 Jan 00
|     (C)Copyright, JJU Research, 2000.
|
|     Description:
|       Form the adjoint of a real (4x4) matrix.
|
|     Access:
|       (void) adj44c(real *a, real *adj);
|     real a[4,4],i-The matrix whose adjoint is desired.
|     real adj[4,4],o-The adjoint of matrix a.
|
|     Error Conditions:
|       None.
|
|     Comments:
|       None.
*
*     History:
*     01 Jan 00:JJU-Original.
* ------------------------------------------------------------------- */
 
#include "..\libcad\libcad.h"
#ifdef ANSI
  void adj44c(real a[4][4], real adj[4][4])
#else
  void adj44c(a, adj)
  real a[4][4], adj[4][4];
#endif
{
  adj[0][0] = a[1][1] * (a[2][2] * a[3][3] - a[2][3] * a[3][2])
            + a[1][2] * (a[2][3] * a[3][1] - a[2][1] * a[3][3])
            + a[1][3] * (a[2][1] * a[3][2] - a[2][2] * a[3][1]);
  adj[0][1] = a[0][1] * (a[2][3] * a[3][2] - a[2][2] * a[3][3])
            + a[0][2] * (a[2][1] * a[3][3] - a[2][3] * a[3][1])
            + a[0][3] * (a[2][2] * a[3][1] - a[2][1] * a[3][2]);
  adj[0][2] = a[0][1] * (a[1][2] * a[3][3] - a[1][3] * a[3][2])
            + a[0][2] * (a[1][3] * a[3][1] - a[1][1] * a[3][3])
            + a[0][3] * (a[1][1] * a[3][2] - a[1][2] * a[3][1]);
  adj[0][3] = a[0][1] * (a[1][3] * a[2][2] - a[1][2] * a[2][3])
            + a[0][2] * (a[1][1] * a[2][3] - a[1][3] * a[2][1])
            + a[0][3] * (a[1][2] * a[2][1] - a[1][1] * a[2][2]);
  adj[1][0] = a[1][0] * (a[2][3] * a[3][2] - a[2][2] * a[3][3])
            + a[1][2] * (a[2][0] * a[3][3] - a[2][3] * a[3][0])
            + a[1][3] * (a[2][2] * a[3][0] - a[2][0] * a[3][2]);
  adj[1][1] = a[0][0] * (a[2][2] * a[3][3] - a[2][3] * a[3][2])
            + a[0][2] * (a[2][3] * a[3][0] - a[2][0] * a[3][3])
            + a[0][3] * (a[2][0] * a[3][2] - a[2][2] * a[3][0]);
  adj[1][2] = a[0][0] * (a[1][3] * a[3][2] - a[1][2] * a[3][3])
            + a[0][2] * (a[1][0] * a[3][3] - a[1][3] * a[3][0])
            + a[0][3] * (a[1][2] * a[3][0] - a[1][0] * a[3][2]);
  adj[1][3] = a[0][0] * (a[1][2] * a[2][3] - a[1][3] * a[2][2])
            + a[0][2] * (a[1][3] * a[2][0] - a[1][0] * a[2][3])
            + a[0][3] * (a[1][0] * a[2][2] - a[1][2] * a[2][0]);
  adj[2][0] = a[1][0] * (a[2][1] * a[3][3] - a[2][3] * a[3][1])
            + a[1][1] * (a[2][3] * a[3][0] - a[2][0] * a[3][3])
            + a[1][3] * (a[2][0] * a[3][1] - a[2][1] * a[3][0]);
  adj[2][1] = a[0][0] * (a[2][3] * a[3][1] - a[2][1] * a[3][3])
            + a[0][1] * (a[2][0] * a[3][3] - a[2][3] * a[3][0])
            + a[0][3] * (a[2][1] * a[3][0] - a[2][0] * a[3][1]);
  adj[2][2] = a[0][0] * (a[1][1] * a[3][3] - a[1][3] * a[3][1])
            + a[0][1] * (a[1][3] * a[3][0] - a[1][0] * a[3][3])
            + a[0][3] * (a[1][0] * a[3][1] - a[1][1] * a[3][0]);
  adj[2][3] = a[0][0] * (a[1][3] * a[2][1] - a[1][1] * a[2][3])
            + a[0][1] * (a[1][0] * a[2][3] - a[1][3] * a[2][0])
            + a[0][3] * (a[1][1] * a[2][0] - a[1][0] * a[2][1]);
  adj[3][0] = a[1][0] * (a[2][2] * a[3][1] - a[2][1] * a[3][2])
            + a[1][1] * (a[2][0] * a[3][2] - a[2][2] * a[3][0])
            + a[1][2] * (a[2][1] * a[3][0] - a[2][0] * a[3][1]);
  adj[3][1] = a[0][0] * (a[2][1] * a[3][2] - a[2][2] * a[3][1])
            + a[0][1] * (a[2][2] * a[3][0] - a[2][0] * a[3][2])
            + a[0][2] * (a[2][0] * a[3][1] - a[2][1] * a[3][0]);
  adj[3][2] = a[0][0] * (a[1][2] * a[3][1] - a[1][1] * a[3][2])
            + a[0][1] * (a[1][0] * a[3][2] - a[1][2] * a[3][0])
            + a[0][2] * (a[1][1] * a[3][0] - a[1][0] * a[3][1]);
  adj[3][3] = a[0][0] * (a[1][1] * a[2][2] - a[1][2] * a[2][1])
            + a[0][1] * (a[1][2] * a[2][0] - a[1][0] * a[2][2])
            + a[0][2] * (a[1][0] * a[2][1] - a[1][1] * a[2][0]);
  return;
}
